package com.xxgc.cloud.error.center.error;

import com.xxgc.cloud.error.center.GlobalException;
import com.xxgc.cloud.error.center.result.ErrResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: SpringCloudStudy
 * @description: Shiro异常处理
 * @author: Shijiayi
 * @create: 2022-12-13 14:32
 **/
@Slf4j
@ControllerAdvice
@ResponseBody
public class ShiroException extends GlobalException {
    /**
     * 没有权限
     * @param e
     * @return
     */
    @ExceptionHandler(value = {AuthorizationException.class})
    public ErrResult<AuthorizationException> authorizationException(AuthorizationException e){
        log.error(e.toString());
        String msg = active.equals(myActive) ? system : NOT_AUTHORIZED_MSG;
        return ErrResult.error(msg,NOT_AUTHORIZED_CODE);
    }

}
